package com.situ.day2;

import org.junit.Test;

import java.util.*;

public class CollectionDemo {
    @Test
    public void test1() {
        //List:有序可重复
        //ArrayList<Student> list = new ArrayList<>();
        List<Student> list = new ArrayList<>();
        Student student1 = new Student(1, "zhangsan1", 23);
        Student student2 = new Student(2, "zhangsan2", 23);
        Student student3 = new Student(3, "zhangsan3", 23);
        Student student4 = new Student(4, "zhangsan4", 23);
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student4);
        for (Student student : list) {
            System.out.println(student);
        }


        List<String> list1 = new ArrayList<String>();
        list1.add("Java");
        list1.add("UI");
        list1.add("H5");
        list1.add("H5");
        list1.add("aa");
        for (String str : list1) {
            System.out.println(str);
        }

        System.out.println("==================");
        Set<String> set = new HashSet<>();
        set.add("Java");
        set.add("UI");
        set.add("H5");
        set.add("H5");
        set.add("aa");
        for (String str : set) {
            System.out.println(str);
        }
    }

    @Test
    public void test323() {
        Map<String, String> map = new HashMap<>();
        map.put("cn", "中国");
        map.put("us", "美国");
        String value = map.get("cn");
        System.out.println(value);
        Set<Map.Entry<String, String>> set = map.entrySet();
        for (Map.Entry<String, String> entry : set) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }


    @Test
    public void test223() {
        Map<String, String> map = new HashMap<>();
        map.put("cn", "中国");
        map.put("us", "美国");
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {//判断有没有下一个
            Map.Entry<String, String> entry = iterator.next();//指向下一个
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }

    @Test
    public void test324() {
        Map<String, String> map = new HashMap<>();
        map.put("cn", "中国");
        map.put("us", "美国");
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println(key + "=" + map.get(key));
        }
    }



}
